getFoodInfo();

//根据id查询菜品信息
function getFoodInfo(){
	var Request = new Object();
	Request = GetRequest();
	var id = Request['id'];

	var obj = JSON.stringify({
		"id": id,
	});

	httpHelperpost(_API_FOOD_INFO, obj, function(isSuccess, data) {
	    if (isSuccess == true) {
	        var response = data.responseText;
	        var value = JSON.parse(response);
	   			
	   		// console.log(response);
	   		$(".food-name").text(value.data.name);
	   		$(".food-money").text("￥"+value.data.price);
	   		$(".desc-detail").text(value.data.remark);

	        if(value.code == 0){
	            console.log("查询成功");
	            	
	        }else if(value.code==401){
	            alert(value.message);
	            window.location.href='./index.html';
	        }else{
	            console.log("查询失败");
	        }
	    }else {}
	});
}

findFoodEvaluationList();
// 菜品评论列表
function findFoodEvaluationList(){
	var page = 0;
	var size = 5;
	
	var sort = new Array();
	sort.push("id");

	var Request = new Object();
	Request = GetRequest();
	var id = Request['id'];

	var obj = JSON.stringify({
		"foodId": id,
	});

	httpHelperpost(_API_FOOD_EVALUATION_LIST+"?page="+page+"&size="+size+"&sort="+sort, obj, function(isSuccess, data) {
	    if (isSuccess == true) {
	        var response = data.responseText;
	        var value = JSON.parse(response);
	   			
	   		console.log(response);
	   		var commentHtml = "";
	   		for(var i=0;i<value.data.content.length;i++){
	   			var evaluationTime = value.data.content[i].evaluationTime.substring(0,10);
	   			
	   			commentHtml += "<li class='desc-li'>"
	   						+"<div class='desc-bar'>"
	   						+"<div class='desc-bar-img'><img class='imgBai' src='./img/root_04.png'></div>"
	   						+"<div class='desc-bar-state'>"
	   						+"<div>"+value.data.content[i].userName+"</div>"
	   						+"<div><img src='./img/zan_01.png'>赞了该商品</div>"
	   						+"</div>"
	   						+"<div class='desc-bar-date'>"+evaluationTime+"</div>"
	   						+"</div>"
	   						+"<div class='desc-li-text'>"+value.data.content[i].evaluationContent+"</div>"
	   						+"</li>";
	   		}
	   		$(".desc ul").html(commentHtml);

	        if(value.code == 0){
	        	alert(value.message);
	            console.log("查询成功");
	            	
	        }else if(value.code==401){
	           	alert(value.message);
	           	window.location.href='./index.html';
	        }else{
	            console.log("查询失败");
	        }
	    }else {}
	});
}



//获取url中"?"符后的字串
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串   
    
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      
      strs = str.split("&");
      
      for (var i = 0; i < strs.length; i++) {
        
        theRequest[strs[i].split("=")[0]] = strs[i]
            .split("=")[1];
      }
    }
    return theRequest;
}